﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.OpenGL;
using System.IO;
using System.Reflection;
using Silvermoon.Visuals;
using System.Drawing;

namespace Silvermoon.Images
{
    public static class SysImages
    {
        private static Texture progressBorder;
        private static Texture keyboard;
        private static Texture upImage;
        private static Texture downImage;
        private static Texture leftImage;
        private static Texture rightImage;
        private static Texture checkedImage;
        private static Texture uncheckedImage;
        private static Texture menuBackground;
        private static Texture buttonBackground;
        private static Texture itemBackground;
        private static Texture textBox;
        private static Texture textBoxSel;
        private static Texture rectangle;
        private static Texture gripper;
        private static Texture subItemArrow;
        private static Texture roundAtTop;
        private static Texture roundAtBottom;
        private static Texture lens;
        private static Texture check;
        private static Texture point;
        private static Texture busy;
        private static Texture flagCorners;
        private static Texture glowButton;
        private static Texture tooltip;
        private static Texture toolTipArrowDown;
        private static Texture toolTipArrowUp;
        private static Texture cut, copy, paste;

        public static Texture ProgressBorder
        {
            get
            {
                if (progressBorder == null) progressBorder = CreateImage("ProgressBorder");
                return progressBorder;
            }
        }

        public static Texture Lens
        {
            get
            {
                if (lens == null) lens = CreateImage("Lens");
                return lens;
            }
        }

        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture FlatCorners
        {
            get
            {
                if (flagCorners == null) flagCorners = CreateImage("FlatCorners");
                return flagCorners;
            }
        }
        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture RoundAtBottom
        {
            get
            {
                if (roundAtBottom == null) roundAtBottom = CreateImage("RoundAtBottom");
                return roundAtBottom;
            }
        }

        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture RoundAtTop
        {
            get
            {
                if (roundAtTop == null) roundAtTop = CreateImage("RoundAtTop");
                return roundAtTop;
            }
        }

        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture TextBox
        {
            get
            {
                if (textBox == null) textBox = CreateImage("TextBox");
                return textBox;
            }
        }

        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture SelectedTextBox
        {
            get
            {
                if (textBoxSel == null) textBoxSel = CreateImage("TextBoxSelected");
                return textBoxSel;
            }
        }

        /// <summary>
        /// Gets the 16x16 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture Gripper
        {
            get
            {
                if (gripper == null) gripper = CreateImage("Gripper");
                return gripper;
            }
        }

        /// <summary>
        /// Gets the 16x16 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        /// <value>The text box.</value>
        public static Texture Rectangle
        {
            get
            {
                if (rectangle == null) rectangle = CreateImage("Rectangle");
                return rectangle;
            }
        }

        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        public static Texture Button
        {
            get
            {
                if (buttonBackground == null) buttonBackground = CreateImage("Button");
                return buttonBackground;
            }
        }

        public static Texture GlowButton
        {
            get
            {
                if (glowButton == null) glowButton = CreateImage("GlowButton");
                return glowButton;
            }
        }

        public static Texture ItemBackground
        {
            get
            {
                if (itemBackground == null) itemBackground = CreateImage("ItemBackground");
                return itemBackground;
            }
        }

        /// <summary>
        /// Gets the 32x32 image that contains the 4 quadrants to be used with a <see cref="T:FourQuadrantVisual"/>.
        /// </summary>
        public static Texture MenuBackground
        {
            get
            {
                if (menuBackground == null) menuBackground = CreateImage("menuBg");
                return menuBackground;
            }
        }

        public static Texture ToolTip
        {
            get
            {
                if (tooltip == null) tooltip = CreateImage("ToolTip");
                return tooltip;
            }
        }

        public static Texture Keyboard
        {
            get
            {
                if (keyboard == null)
                {
                    keyboard = CreateImage("Keyboard");
                    //keyboard.Size = new Size(48, 48);
                }
                return keyboard;
            }
        }

        public static Texture UpImage
        {
            get
            {
                if (upImage == null) upImage = CreateImage("ArrowUp");
                return upImage;
            }
        }

        public static Texture DownImage
        {
            get
            {
                if (downImage == null) downImage = CreateImage("ArrowDown");
                return downImage;
            }
        }

        public static Texture LeftImage
        {
            get
            {
                if (leftImage == null) leftImage = CreateImage("ArrowLeft");
                return leftImage;
            }
        }

        public static Texture RightImage
        {
            get
            {
                if (rightImage == null) rightImage = CreateImage("ArrowRight");
                return rightImage;
            }
        }

        public static Texture CheckBox
        {
            get
            {
                if (uncheckedImage == null) uncheckedImage = CreateImage("CheckBox");
                return uncheckedImage;
            }
        }

        public static Texture Check
        {
            get
            {
                if (check == null) check = CreateImage("Check");
                return check;
            }


        }

        public static Texture Point
        {
            get
            {
                if (point == null) point = CreateImage("Point");
                return point;
            }
        }



        public static Texture Copy
        {
            get
            {
                if (copy == null) copy = CreateImage("Copy");
                return copy;
            }
        }

        public static Texture Cut
        {
            get
            {
                if (cut == null) cut = CreateImage("Cut");
                return cut;
            }
        }

        public static Texture Paste
        {
            get
            {
                if (paste == null) paste = CreateImage("Paste");
                return paste;
            }
        }


        internal static Texture Busy
        {
            get
            {
                if (busy == null) busy = CreateImage("Busy");
                return busy;
            }
        }

        public static Texture ToolTipArrowDown
        {
            get
            {
                if (toolTipArrowDown == null) toolTipArrowDown = CreateImage("ToolTipArrow");
                return toolTipArrowDown;
            }
        }

        public static Texture ToolTipArrowUp
        {
            get
            {
                if (toolTipArrowUp == null) toolTipArrowUp = CreateImage("ToolTipArrowUp");
                return toolTipArrowUp;
            }
        }

        public static Texture SubItemArrow
        {
            get
            {
                if (subItemArrow == null) subItemArrow = CreateImage("Arrow");
                return subItemArrow;
            }
        }

        public static Texture CheckedCheckBox
        {
            get
            {
                if (checkedImage == null) checkedImage = CreateImage("CheckBoxChecked");
                return checkedImage;
            }
        }


        private static Texture CreateImage(string name)
        {
            string resource = string.Format("Silvermoon.Images.{0}.png", name);
            Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream(resource);
            if (stream == null) throw new SystemException("Resource " + resource + " not found.");
            Texture image = new Texture();
            image.LoadFromStream(stream);

            return image;
        }


    }
}
